//
//  LZRestaurantDetailModel.m
//  laziz_Consumer
//
//  Created by xbn_iMac on 2016/11/28.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZRestaurantDetailModel.h"
#import "AppDelegate.h"
#import "LZHomePageViewController.h"
#import "LZCuisineModel.h"

@implementation LZRestaurantDetailModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"restaurantId": @"id"};
}


+ (NSDictionary *)mj_objectClassInArray
{
    return @{
             @"sellerPhotoAlbums" : @"LZSellerPhotoAlbumsModel",
             };
}


- (void)changeCuisineNameByCuisineID
{
    if (self.cookingStyle.length == 0) {
        return ;
    }
    
    NSString *resultStr = @"";
    NSArray *idArr = [self.cookingStyle componentsSeparatedByString:@","];
    
    NSArray *cuisineDataArr = [self getLocalCuisineData];
    
    for (int i = 0; i < idArr.count; i ++) {
        NSString *idStrTemp = idArr[i];
        
        NSArray *arrResult = [cuisineDataArr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.cuisineID = %@",idStrTemp]];
        
        if (arrResult.count>0) {
            LZCuisineModel *m = arrResult[0];
            if (i == idArr.count - 1) {
                resultStr = [resultStr stringByAppendingString:m.name];
            }else{
                resultStr = [resultStr stringByAppendingString:[NSString stringWithFormat:@"%@,",m.name]];
            }
        }
    }
    
    self.cookingStyle = resultStr;
}

- (NSArray*)getLocalCuisineData
{
    AppDelegate *del = (AppDelegate *) [UIApplication sharedApplication].delegate;
    UITabBarController *rootVc = (UITabBarController *) del.window.rootViewController;
    UINavigationController *navVc = rootVc.viewControllers[0];
    for (id vc in navVc.viewControllers) {
        if ([vc isKindOfClass:[LZHomePageViewController class]]) {
            LZHomePageViewController *homeVc = (LZHomePageViewController *) vc;
            return homeVc.cuisineArr;
        }
    }
    return @[];
}


@end
